
import Vue from 'vue';
// 引入element UI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App';
// 引入路由
import router from './router';

// 引入icon
import './assets/icon/iconfont.css'
// 
import axios from 'axios';
axios.defaults.baseURL = '127.0.0.1:8081';
Vue.prototype.$http = axios;

Vue.config.productionTip = false;

// 使用element UI
Vue.use(ElementUI);
Vue.prototype.$message=ElementUI.Message

// //过滤器
// import * as custom from './utils/util'

// Object.keys(custom).forEach(key => {
//     Vue.filter(key, custom[key])
// })


const qs = require('qs');
Vue.prototype.$qs=qs;

//路由守卫
router.beforeEach((to, form, next) => {
    if (to.path === '/login' || to.path === '/register') return next()
    const tokenStr = window.sessionStorage.getItem('userInfo')
    if (!tokenStr) {
      ElementUI.Message.warning('请先登录')
      next('/login')
    } else {
      next()
    }
  })


new Vue({
    el: '#app',
    router,
    components: { App },
    template: '<App/>',
    data: {
        // 空的实例放到根组件下，所有的子组件都能调用
        Bus: new Vue()
    }

})